var picArr = ["1", "2", "3", "4", "5", "6"];

var img = document.getElementById("pic");
var forwardBtn = document.getElementById("forward");
var backwardBtn = document.getElementById("backward");

var counter = 0;

function changeImageForward() {
    return  function() {
        if (counter === picArr.length-1) {
            return;
        }
        counter++;
        img.src = "images/" + picArr[counter] + ".jpg";
    };
}

function changeImageBackward() {
    return function() {
        if (counter < 1) {
            return;
        }
        counter--;
        img.src = "images/" + picArr[counter] + ".jpg";
    };
}
forwardBtn.onclick = changeImageBackward();
backwardBtn.onclick = changeImageForward();